package com.yunsc.admin.controller.market;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.order.dto.RechargePlanDTO;
import com.yunsc.order.entity.YunscRechargePlanEntity;
import com.yunsc.order.sevice.YunscRechargePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-06-03 21:54
 */
@Api(tags = "充值方案")
@RestController
@RequestMapping("/market/recharge/plan")
public class RechargePlanController {


    @Resource
    private YunscRechargePlanService rechargePlanService;

    // list 充值方案列表
    @ApiOperation(value = "充值方案列表", notes = "充值方案列表")
    @RequestMapping("/list")
    public Result<?> queryRechargePlanList(RechargePlanDTO param) {
        Integer storeId = SecurityUtil.getCurrentStoreId();
        PageResult<YunscRechargePlanEntity> pageResult = rechargePlanService.queryRechargePlanList(param, storeId);
        return Result.resultPageList(pageResult);
    }

    // add 保存充值方案
    @ApiOperation(value = "保存充值方案", notes = "保存充值方案")
    @RequestMapping("/add")
    public Result<?> addRechargePlan(@RequestBody RechargePlanDTO param) {
        Integer storeId = SecurityUtil.getCurrentStoreId();
        rechargePlanService.addRechargePlan(param.getForm(), storeId);
        return Result.ok("保存成功");
    }

    // edit 修改充值方案
    @ApiOperation(value = "修改充值方案", notes = "修改充值方案")
    @RequestMapping("/edit")
    public Result<?> editRechargePlan(@RequestBody @Validated(ValidationGroups.Update.class) RechargePlanDTO param) {
        rechargePlanService.editRechargePlan(param);
        return Result.ok("修改成功");
    }

    // delete 删除充值方案
    @ApiOperation(value = "删除充值方案", notes = "删除充值方案")
    @RequestMapping("/delete")
    public Result<?> deleteRechargePlan(@RequestBody @Validated(ValidationGroups.Delete.class) RechargePlanDTO param) {
        rechargePlanService.deleteRechargePlan(param.getPlanId());
        return Result.ok("删除成功");
    }




}
